
********************************************************************************
************************* Data prep survey ****************
********************************************************************************
use "$data/telephone_surveydata" , clear


* Note: A small mean-zero error term has been added to the accounting data, to ensure confidentiality of the survey data. The empirical results are robust to these changes.
* Dummy variables in the survey data have been randomized and thus have meaningful interpretation. 

gen timepassed=(92-lasttreated)+surveyday // This measures time between last sticker received and date of survey
replace timepassed= timepassed-28 // demeaning
replace timepassed= timepassed/7 // scale to weeks

sum q8 if treatmentall==1 | treatmentall==2
gen q8normalized=(q8-4.358491)/.6485665  // normalized


** For entropy balancing **
gen ebal_highvisible=1 if stickerplacement==1 
replace ebal_highvisible=0 if stickerplacement==3 | stickerplacement==2  // 1= Outside // 2 Inside // 3 Mailbox 
replace ebal_highvisible=2 if stickerplacement==0  // 

**
xtile avgpaydatedummymedian = avgpaydatedummy, nq(2)
replace avgpaydatedummymedian=avgpaydatedummymedian-1 if avgpaydatedummy!=.
replace avgpaydatedummymedian=2 if avgpaydatedummy==. 

xtile avgweighteddaymedian = avgweightedday, nq(2)
replace avgweighteddaymedian=avgweighteddaymedian-1 if avgweighteddaymedian!=.
replace avgweighteddaymedian=2 if avgweightedday==. 

 
** PCA ***
pca q8 q9
rotate
predict idindex

save "$data/telephone_surveydata_ready" , replace








